import Vuex from 'vuex';
import Vue from 'vue';
import { baseUrl } from '../config/env';

Vue.use(Vuex);


var imgPrefix = baseUrl + '/storage/';

/* if (process.env.NODE_ENV == 'production') {//生产环境
  imgPrefix = '/storage/';
} else { //开发环境 dev

  imgPrefix = baseUrl + '/storage/';
} */

const state = {
  count: 0,
  menu: [],
  todos: [
    { id: 1, text: '...', done: true },
    { id: 2, text: '...', done: false },
    { id: 3, text: '44444', done: true }
  ],
  imgPrefix: imgPrefix,
};

const getters = {
  doneTodos: state => {
    return state.todos.filter(todo => todo.done);
  },
  doneTodosCount: (state, getters) => {
    return getters.doneTodos.length;
  },
  imgPrefix: state => state.imgPrefix,
};

const mutations = {
  increment (state) {
    state.count++;
  }
};


export default new Vuex.Store({
  state,
  mutations,
  getters,
});